package com.ieds.modules.common.elasticsearch;

import com.ieds.modules.common.Util.StringUtil;
import org.apache.log4j.Logger;

import java.io.*;

/**
 * 全文检索txt转换文本
 * @author hugejile
 * @version 20200903
 */
public class TxtFileTextExtrator {

	/**
	 * 创建log对象
	 */
	private static final Logger log = Logger.getLogger(TxtFileTextExtrator.class);

	public static String getText(File file) throws IOException {
		StringBuffer strBuf= new StringBuffer();
		String tempStr="";
		try(FileInputStream in = new FileInputStream(file)) {
			if (in != null) {
				try(BufferedReader reader =   new BufferedReader(new InputStreamReader(in,"GBK"))) {
					while((tempStr=reader.readLine())!=null){
						strBuf.append(tempStr);
					}
				} catch (UnsupportedEncodingException e) {
					log.error("getText() 失败！", e);
				}
			}
		} catch (FileNotFoundException e) {
			log.error("getText() 失败！", e);
		}

		return StringUtil.washString(strBuf.toString());
	}

	/*public static void main(String[] args) throws IOException {
		File file = new File("E:\\ceshi\\ceshi.txt");
		TxtFileTextExtrator.getText(file);
	}*/


}
